from selenium import webdriver
from time import sleep
driver = webdriver.Firefox()
driver.get('https://www.baidu.com/')
sleep(2)

driver.find_element_by_partial_link_text('新闻').click()
sleep(2)

hds = driver.window_handles
print(hds)
# 进入新闻界面
driver.switch_to_window(hds[1])
sleep(2)

driver.find_element_by_partial_link_text('军事').click()
sleep(2)

# 进入军事页面
driver.switch_to_window(hds[1])
sleep(2)

driver.find_element_by_partial_link_text('轰炸机').click()
sleep(2)

driver.close()
driver.switch_to_window(hds[0])

driver.find_element_by_id('kw').send_keys('Selenium')
driver.find_element_by_id('su').click()
sleep(2)

driver.quit()